#include <iostream>
#include <algorithm> 
#include <cmath>
#include <cstdlib>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>

using namespace std;
#define ll long long

bool check(int year) {
    return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}

int main()
{
    unordered_set<int> square = { 1, 4, 9, 16, 25, 36, 49, 64 };

    // 0 1 2 3 4 5 6 7
    // 2 0 0 1 0 1 0 1 -> 20211231
    string str("20010101");
    string end("20211231");
    int ret = 0;
    int monthday[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    while (str != end) {
        int curnum = 0;
        for (int i = 0; i < 8; ++i) {
            curnum += str[i] - '0';
        }
        if (square.count(curnum)) {
            ret++;
        }
        int year = stoi(str.substr(0, 4));
        if (check(year)) {
            monthday[2] = 29;
        }
        int month = stoi(str.substr(4, 2));
        int mday = monthday[month];
        int day = stoi(str.substr(6, 2));
        if (day + 1 <= mday) {
            day++;
            if (day <= 9) {
                str[7] = day + '0';
            }
            else if (day == 10) {
                str[6] = '1';
                str[7] = '0';
            }
            else {
                string tmp = to_string(day);
                str[6] = tmp[0];
                str[7] = tmp[1];
            }
        }
        else {
            str[6] = '0';
            str[7] = '1';
            if (month + 1 <= 12) {
                month++;
                if (month <= 9) {
                    str[5] = month + '0';
                }
                else if (month == 10) {
                    str[4] = '1';
                    str[5] = '0';
                }
                else {
                    string tmp = to_string(month);
                    str[4] = tmp[0];
                    str[5] = tmp[1];
                }
            }
            else {
                str[4] = '0';
                str[5] = '1';
                year++;
                string tmp = to_string(year);
                str[0] = tmp[0];
                str[1] = tmp[1];
                str[2] = tmp[2];
                str[3] = tmp[3];
            }
        }

        monthday[2] = 28;
    }
    cout << ret;

    return 0;
}